package manage.controller;

import com.alibaba.fastjson.JSONObject;
import manage.base.BaseController;
import manage.model.Position;
import manage.service.PoitionServcie;
import manage.service.impl.PositionServcieImp;
import manage.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author: create by  Raphaelkxy
 * @version: v1.0
 * @description: manage.controller
 * @date:2019/8/28
 */

@Controller
public class PositionController extends BaseController {

    @Autowired
    private PoitionServcie positionServcie;

    //列表
    @RequestMapping(value = "/getPositionList",produces = "text/html;charset=UTF-8",method = RequestMethod.GET)
    @ResponseBody
    public String getLists(HttpServletRequest request,HttpSession session){
        String pageSize = request.getParameter("pageSize");
        String currentPage = request.getParameter("currentPage");
        PageInfo page = getPage(pageSize, currentPage);
        List<Position>positions = positionServcie.getAll();
        HashMap result = new HashMap();
        result.put("arrayList", positions);
        result.put("pageInfo", page);
        return   JSONObject.toJSONString(result);
    }
    //查询
    @RequestMapping(value = "/insertposition",method = RequestMethod.POST)
    @ResponseBody
    public String insertPosition(Position position,HttpServletRequest request,HttpSession session){
        position.setFabuzhuangtai(0);
        position.setShenhezhuangtai(0);
        int i = positionServcie.insertrecord(position);
        if(i>0)
            return  JSONObject.toJSONString("success");
        else
            return  JSONObject.toJSONString("fail");
    }
    //删除
    @RequestMapping(value = "/deleteByid",method = RequestMethod.DELETE)
    @ResponseBody
    public String delete(@RequestBody String id){
        int i = positionServcie.deleteByPrimaryKey(Integer.parseInt(id));
        if(i>0)
            return JSONObject.toJSONString("success");
        else
            return JSONObject.toJSONString("fail");
    }

    //更新
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @ResponseBody
    public String updateItem(@RequestBody Position position, HttpServletRequest request,HttpSession session){
         int i= positionServcie.updateByPrimaryKey(position);
         if(i>0)
             return "success";
         else
             return "fail";
    }

    /**
     * 根据id查询
     */
    @RequestMapping(value = "/getByid",method = RequestMethod.POST)
    @ResponseBody
    public String getByid(@RequestBody Integer id, HttpServletRequest request,HttpSession session){
        Position position= positionServcie.getById(id);
            return  JSONObject.toJSONString(position);

    }


    /**
     * 查询带发布招聘
     */
    @RequestMapping(value = "/getByfabu",produces = "text/html;charset=UTF-8",method = RequestMethod.GET)
    @ResponseBody
    public String getByfabu(HttpServletRequest request,HttpSession session){
        List<Position>positions = positionServcie.getByfabu();
        String pageSize = request.getParameter("pageSize");
        String currentPage = request.getParameter("currentPage");
        PageInfo page = getPage(pageSize, currentPage);
        HashMap result = new HashMap();
        result.put("arrayList", positions);
        result.put("pageInfo", page);
        return   JSONObject.toJSONString(result);

    }

    /**
     * 查询带发布招聘
     */
    @RequestMapping(value = "/getByshenhe",produces = "text/html;charset=UTF-8",method = RequestMethod.GET)
    @ResponseBody
    public String getByshenhe(HttpServletRequest request,HttpSession session){
        List<Position>positions = positionServcie.getByshenhe();
        String pageSize = request.getParameter("pageSize");
        String currentPage = request.getParameter("currentPage");
        PageInfo page = getPage(pageSize, currentPage);
        HashMap result = new HashMap();
        result.put("arrayList", positions);
        result.put("pageInfo", page);
        return   JSONObject.toJSONString(result);

    }

    /**
     * 查询带发布招聘
     */
    @RequestMapping(value = "/getByfabu0",produces = "text/html;charset=UTF-8",method = RequestMethod.GET)
    @ResponseBody
    public String getByfabu0(HttpServletRequest request,HttpSession session){
        List<Position>positions = positionServcie.getByfabu0();
        String pageSize = request.getParameter("pageSize");
        String currentPage = request.getParameter("currentPage");
        PageInfo page = getPage(pageSize, currentPage);
        HashMap result = new HashMap();
        result.put("arrayList", positions);
        result.put("pageInfo", page);
        return   JSONObject.toJSONString(result);

    }

    /**
     * 发布招聘
     */
    @RequestMapping(value = "/fabuzhaopin",produces = "text/html;charset=UTF-8",method = RequestMethod.PUT)
    @ResponseBody
    public String fabuzhaopin(@RequestBody String id){
        Position position = positionServcie.getById(Integer.valueOf(id));
        position.setFabuzhuangtai(1);
        Date date = new Date();
        position.setFabutime(date);
       int i = positionServcie.updateByPrimaryKey(position);
        if(i>0){
            String returnInfo = JSONObject.toJSONString("success");
            return returnInfo;
        }else {
            String returnInfo = JSONObject.toJSONString("fail");
            return returnInfo;

    }}

    /**
     * 审核招聘
     */
    @RequestMapping(value = "/shenhezhaopin",produces = "text/html;charset=UTF-8",method = RequestMethod.PUT)
    @ResponseBody
    public String shenhezhaopin(@RequestBody String id){
        Position position = positionServcie.getById(Integer.valueOf(id));
        position.setShenhezhuangtai(1);
        Date date = new Date();
        position.setShenhetime(date);
        int i = positionServcie.updateByPrimaryKey(position);
        if(i>0){
            String returnInfo = JSONObject.toJSONString("success");
            return returnInfo;
        }else {
            String returnInfo = JSONObject.toJSONString("fail");
            return returnInfo;

        }}
    /**
     * 查询带发布招聘
     */
    @RequestMapping(value = "/getByshenhe0",produces = "text/html;charset=UTF-8",method = RequestMethod.GET)
    @ResponseBody
    public String getByshenhe0(HttpServletRequest request,HttpSession session){
        List<Position>positions = positionServcie.getByshenhe0();
        String pageSize = request.getParameter("pageSize");
        String currentPage = request.getParameter("currentPage");
        PageInfo page = getPage(pageSize, currentPage);
        HashMap result = new HashMap();
        result.put("arrayList", positions);
        result.put("pageInfo", page);
        return   JSONObject.toJSONString(result);

    }
}
